import React from 'react';
import { PlusOutlined, MinusOutlined } from '@ant-design/icons';
import { createStyles } from 'antd-style';

const ZoomTool = ({ scale = 1, onChange }) => {
  const { styles } = useStyles()
  const step = 0.1; // 缩放因子 每次10%

  const percent = `${Math.round(scale * 100)}%`;

  const plus = () => {
    onChange(scale + step);
  };

  const minus = () => {
    onChange(scale - step);
  };

  return (
    <div className={styles + " zoom-tool"}>
      <MinusOutlined onClick={minus} />
      <span>{percent}</span>
      <PlusOutlined onClick={plus} />
    </div>
  );
};

const useStyles = createStyles(({ token, css }) => {
  return css`
      &.zoom-tool {
    width: 112px;
    height: 28px;
    padding: 0 6px;
    background-color: ${token.colorBgBase};
    box-shadow: ${token.boxShadow};
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    font-size: 14px;
    user-select: none;

    position: absolute;
    right: 16px;
    bottom: 16px;

    .el-icon {
      cursor: pointer;
    }
  }
  `
})

export default ZoomTool; 